package com.me.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.me.entity.GroupRemebers;
import com.me.entity.Groups;

@Service
public class GroupService {

	@Autowired
	HibernateTemplate hibernateTemplate;
	
	
	public List getRemebersEntityByUidAndGroupId(int uid,int group_id){
		List list=hibernateTemplate.find("from GroupRemebers where group_id="+group_id+" and uid="+uid);
		return list;
	}
	
	public List getRemembersInfoByGroupId(String id){
		String hql="select account,username,icon,city from UserInfo where id in	"
				+ "(select uid from GroupRemebers where group_id="+id+")";
					
					
	
		List list=hibernateTemplate.find(hql);
		return list;
	}
	public List getRemebersAccountByGroupId(String groupId){
		String hql="select account from UserInfo where id in("
				+ "select uid from GroupRemebers where group_id="+groupId+")";
				List list=hibernateTemplate.find(hql);
		return list;
	}
	public List getGroupInfoByGroupId(int id){
		String hql="from Groups where id="+id;
		List list=hibernateTemplate.find(hql);
		return list;
	}
	
	@Transactional
	public void addGroup(Groups g){
		hibernateTemplate.save(g);
	}
	
	@Transactional
	public void addGroupRemebers(GroupRemebers gr){
		hibernateTemplate.save(gr);
	}
	
	
	@Transactional
	public void deleteRemebers(GroupRemebers gr){
		hibernateTemplate.delete(gr);
	}
	
	
	
}
